<template>
	<view class="collectionCentre">
		<view class="contentEVE">
			<u-tabs :current="current" :list="list1" @change="changeTabs" :lineWidth="0" :inactiveStyle="inactiveStyle" :activeStyle="activeStyle"></u-tabs>
            <!-- 每一项 -->
			<evaluateItem :dataList='dataList' @reportComment="reportComment"></evaluateItem>
		</view>
		<!-- 接口请求失败 -->
		<!-- <view class=""><u-empty v-if="showErr" text="暂无内容" mode="wifi" icon="http://cdn.uviewui.com/uview/empty/wifi.png"></u-empty></view> -->
		<!-- 举报/屏蔽 -->
		<shieldAndReport :sheetShow.sync="sheetShow" :itemDeatil="itemDeatil"></shieldAndReport>
		<empty v-if="dataList.length == 0" bgColor="transparent">
		  <view class="tips" slot="content">暂无内容</view>
		</empty>
	</view>
</template>

<script>
import pageMixin from '@/mixins/pageMixin';
// import { evaluate ,commentSummary} from '@/api/medical/medical.js';
import evaluateItem from '@/components/evaluateItem.vue'
export default {
	mixins: [pageMixin],
	components: {evaluateItem},
	data() {
		return {
			sheetShow:false,
			itemDeatil:{},
			current: 0,
			imgPathOne: 'https://res.jiyaqi.com/pet/miniapp/medical/icon4.png',
			inactiveStyle: {
				color: '#666666',
				fontSize: '24rpx',
				padding: '8rpx 35rpx',
				backgroundColor: 'none',
				borderRadius: '50rpx',
				border: '2rpx solid #DBDBDB'
			},
			activeStyle: {
				color: '#FF5900',
				fontSize: '24rpx',
				padding: '8rpx 35rpx',
				// backgroundColor: 'rgba(1, 188, 141, 0.1)',
				borderRadius: '50rpx',
				border: '2rpx solid #FF5900'
			},
			list1: [
				{
					name: '全部 ',
					type:'',
				},
				{
					name: '好评 ',
					type:'nice',
				},
				{
					name: '中评 ',
					type:'medium',
				},
				{
					name: '差评 ',
					type:'negative',
				}
			],
			searchValue: '',
			dataList: [],
			pageNum: 1, //当前页码
			showErr: false,
			doctorId: '',
			type:'',
		};
	},
	computed: {},
	onLoad(options) {
		console.log('=============',options)
		if (options.id) {
			this.doctorId = options.id;
		}
		this.evaluate();
		// this.commentSummary()
		uni.$on('shieldAndReport', data => {
			console.log('监听到事件来自 update ，携带参数 msg 为：', data);
			if (data.type == 2) {
				this.dataList.forEach((item, index) => {
					if (item && item.id == data.itemDeatil.id) {
						this.$set(this.dataList, index, null);
					}
				});
		        uni.$u.toast('屏蔽成功');
				if (data.itemDeatil.goBack) {
					this.$prePage().$vm.handleData('add');
					// 屏蔽详情数据后返回
					setTimeout(() => {
						this.back();
					}, 1500);
				}
			}
		});

	},
	created(){

	},
	onReachBottom() {
		this.evaluate();
	},
	methods: {
		commentSummary(){
			console.log('=============11111',this.doctorId)
			commentSummary({doctorId:this.doctorId}).then(res=>{
				this.list1[0].name= this.list1[0].name + res.totalCount
				this.list1[1].name= this.list1[1].name + res.niceCount
				this.list1[2].name= this.list1[2].name + res.mediumCount
				this.list1[3].name= this.list1[3].name + res.negativeCount
			})
		},
		search() {
			this.search();
			this.pageNum = 1;
			this.current = -1;
			this.evaluate();
		},
		changeTabs(item) {

			this.current = item.index;
			this.type =item.type
			this.pageNum = 1;
			this.evaluate(this.current);
		},
		evaluate() {
			let params = {
				doctorId: this.doctorId,
				pageEnable: 1, //是否需要分页,0:不分页,1:分页
				pageNum: this.pageNum,
				pageSize: 10
			};
			if(this.type){
				params.type = this.type //评价类型
			}
			evaluate(params)
				.then(res => {
					if (this.pageNum == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.status = 'loadmore';
					if (res.list && res.list <= 0) {
						this.status = 'nomore';
					} else {
						this.pageNum++; //追加页码
					}
					this.dataList = this.dataList.concat(res.list); //追加新数据
					this.showErr = false;
				})
				.catch(err => {
					//联网失败, 结束加载
					console.log(err, '获取数据失败err');
					this.showErr = true;
				});
		},
		//<!-- 举报/屏蔽 -->
		reportComment(item,reportType) {
			console.log('举报/屏蔽',item)
			this.itemDeatil = item;
			this.itemDeatil.reportType = reportType?reportType:7; // 举报类型必填：1-宠圈，2常识，3寻宠/领养/转让" +,4智商/保护联盟,5宠圈/常识/寻宠/领养/转让/联盟评论,6问诊评论,7服务评论
			this.sheetShow = true;
		},
	}
};
</script>

<style lang="scss" scoped>
page {
}
.collectionCentre {
}
.contentEVE {
	padding: 20rpx;
}
::v-deep .u-tabs__wrapper__nav__item {
	padding: 0 5px;
}

</style>
